<?

		$sql['tables'][] = "INNER JOIN geograph_live.gridimage_snippet AS g2s USING (gridimage_id)";

		if (!empty($query['sphinx']) && preg_match('/snippet_id:(\d+)/',$query['sphinx'],$m)) {
			if (is_numeric($m[1])) {
				$sql['wheres'][] = "g2s.snippet_id != ".$m[1];
			}
		}
		
		$sql['order'] = "snippet_id, ".$sql['order'];
		
		
		if (strpos($sql['columns'], ",snippet_id") === FALSE) {
			$sql['columns'] .= ",snippet_id";
		} 
		function searchbreak(&$c,$start='',$end='') {
			static $last;
			static $count;
			static $hidden;

			if (empty($c)) {//its the last one
				if ($last) {
					print $end;
					if ($hidden) {
						print "($hidden hidden images - <a href=\"".linktoself(array('snippet_id'=>$last,'delete'=>array('opt','page')))."\">view all</a>)";
					}
				}
				return;
			}
			
			$snippet_id = $c['snippet_id'];
			
			if ($snippet_id != $last) {
			
				if ($last) {
					print $end;
					if ($hidden) {
						print "($hidden hidden images - <a href=\"".linktoself(array('snippet_id'=>$last,'delete'=>array('opt','page')))."\">view all</a>)";
					}
				}
				
				$shared = getRow("SELECT * FROM geograph_live.snippet WHERE enabled = 1 AND snippet_id = $snippet_id");
				
				if (!empty($shared)) {
					print "<h4>".he($shared['title']);
					print " <small>(<a href=\"http://www.geograph.org.uk/snippet/$snippet_id\">View Shared Description Page</a>)</small>";
					//TODO add link to filter... 
					print "</h4>";
					
					print "<p><small>".GeographLinks(he($shared['comment']))."</small></p>";
					
				} else {
					print "<h4>Unknown</h4>";
				}
				print $start;
				$count = 1;
				$hidden =0;
			} else {
				$count++;
				if ($count > 4) {
					$GLOBALS['opt']['has_hidden'] = true;
					$GLOBALS['resultCount']--;
					$hidden++;
					return false;
				}
			}
			
			$last = $snippet_id;
			return true; //we dont disable any images...
		}
		
		$opt['opt'] = 'shared';